package com.fliangyun.nsa.nsamanage.web;

import lombok.Data;

/**
 * @author fuliangyun@139.com
 * @date 2023年05月30日
 * @description
 */
@Data
public class Result<T> {
    private Integer code;
    private String msg;
    private boolean success;
    private T data;

    /**
     * 成功
     * @author fuliangyun@139.com
     * @date 2023-05-30 8:50
     * @param
     * @return Result<?>
     */
    public static <T> Result<T> success(){
        return success("操作成功", null);
    }

    /**
     * 成功
     * @author fuliangyun@139.com
     * @date 2023-05-30 8:50
     * @param
     * @return Result<?>
     */
    public static <T> Result<T> success(T data){
        return success("操作成功", data);
    }

    /**
     * 成功
     * @author fuliangyun@139.com
     * @date 2023-05-30 8:50
     * @param
     * @return Result<?>
     */
    public static <T> Result<T> success(String msg, T data){
        Result<T> result = new Result<>();
        result.success = true;
        result.msg = msg;
        result.code = 200;
        result.data = data;
        return result;
    }

    /**
     * 失败
     * @author fuliangyun@139.com
     * @date 2023-05-30 8:50
     * @param
     * @return Result<?>
     */
    public static <T> Result<T> fail(String msg, int code){
        Result<T> result = new Result<>();
        result.success = false;
        result.msg = msg;
        result.code = code;
        return result;
    }

    /**
     * 失败
     * @author fuliangyun@139.com
     * @date 2023-05-30 8:50
     * @param
     * @return Result<?>
     */
    public static <T> Result<T> fail(){
        return fail("操作失败", 0);
    }

    /**
     * 失败
     * @author fuliangyun@139.com
     * @date 2023-05-30 8:50
     * @param
     * @return Result<?>
     */
    public static <T> Result<T> fail(String msg){
        return fail(msg, 0);
    }
}
